// pages/inpram/cl/businessCondition/businessCondition.js
import { $wuxCalendar } from '../../../../dist/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value1: ['2020-01-01'],
    value2: ['2020-01-30'],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   

  },

  openCalendar1() {
    $wuxCalendar().open({
      value: this.data.value1,
      onChange: (values, displayValues) => {
        console.log('onChange', values, displayValues)
        this.setData({
          value1: displayValues,
        })
      },
    })
  },
  openCalendar2() {
    $wuxCalendar().open({
      value: this.data.value2,
      // multiple: true,
      onChange: (values, displayValues) => {
        console.log('onChange', values, displayValues)
        this.setData({
          value2: displayValues,
        })
      },
    })
  },
  // 时间比较函数
  compareDate: function (startDate, endDate) {
    var arrStart = startDate.split("-");
    var startTime = new Date(arrStart[0], arrStart[1], arrStart[2]);
    var startTimes = startTime.getTime();
    var arrEnd = endDate.split("-");
    var endTime = new Date(arrEnd[0], arrEnd[1], arrEnd[2]);
    var endTimes = endTime.getTime();
    if (endTimes <= startTimes) {
      return false;
    }
    return true;
  },
  /**
   * 检查参数是否合法
   */
  determine: function () {
    var that = this
    var day = that.compareDate(that.data.value1[0], that.data.value2[0]);
    console.log('day', day)
    if (!day) {
      wx.showModal({

        title: '提示',

        content: '开始时间必须小于结束时间一天',

      })

    } else {
    wx.redirectTo({
      url: '../../../view/cl/businessCondition/businessCondition?startTime=' + this.data.value1[0] + '&endTime=' + this.data.value2[0]
    })
    }
  },
  cancel: function () {
    wx.navigateBack({ changed: true });
  }
})